package com.frank.config;

import com.frank.ColorFactoryBean;
import com.frank.MyImportBeanDefinition;
import com.frank.MyImportSelector;
import com.frank.condition.LinuxCondition;
import com.frank.condition.WindowsCondition;
import com.frank.entity.BeanLife;
import com.frank.entity.Color;
import com.frank.entity.User;
import org.springframework.context.annotation.*;

/**
 * @Author: huweifeng
 * @Date: 2022/11/26
 * @Description:
 **/
// 表明这是一个配置类
//@Configuration
@ComponentScan(basePackages = {"com.frank"})
// 导入组件
@Import({Color.class, MyImportSelector.class, MyImportBeanDefinition.class})
public class SystemConfig {
    // 表示返回一个对象
    @Bean
    public User user() {
        return new User("Frank", 28);
    }

    // 条件注解
    @Bean("Bill Gail")
    @Conditional({WindowsCondition.class})
    public User user1() {
        return new User("Bill Gail", 54);
    }

    @Bean("Linus")
    @Conditional({LinuxCondition.class})
    public User user2() {
        return new User("Linus", 48);
    }

    @Bean
    public ColorFactoryBean colorFactoryBean() {
        return new ColorFactoryBean();
    }

    @Bean(initMethod = "init", destroyMethod = "destroy")
    public BeanLife beanLife() {
        return new BeanLife();
    }
}
